package com.keray.web.push.worker.impl;


import com.keray.web.push.ClientData;
import com.keray.web.push.MessageType;
import com.keray.web.push.WebSocket;
import com.keray.web.push.worker.AbstractSocketWorker;
import com.keray.web.push.worker.SocketWorker;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import javax.websocket.Session;

/**
 * @author by keray
 * date:2021/7/23 9:53 上午
 */
@Slf4j
@Configuration
public class HeartSocketWorker implements SocketWorker {


    @Resource
    protected WebSocket webSocket;

    @Override
    public MessageType activeType() {
        return MessageType.heart;
    }

    @Override
    public void onMessage(String message, Session session, ClientData data) {
        if ("heart".equals(message)) {
            webSocket.asyncSend("HEART_OK", session);
        }
    }
}
